package cursojava.io;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ExampleIO {
	
	public List<String> readData() throws IOException{
		Scanner sc = new Scanner(new FileReader("myFiles\\A.in"));
		
		int numeroFilas = sc.nextInt();
		String color1;
		String color2;
		String colorResultado;
		List<String> lista = new ArrayList<String>();
		
		for (int i = 0; i < numeroFilas; i++) {
			color1 = sc.next();
			color2 = sc.next();
			colorResultado = sc.next();
			
			lista.add(color1 + " + " + color2 + " = " + colorResultado);
		}
		sc.close(); //cerrar el archivo
		
		return lista;
	}
	
	public void saveData(List<String> data) throws IOException{
		PrintWriter pw = new PrintWriter(new FileWriter("myFiles\\A.out"));
		
		for (int i = 0; i < data.size(); i++) {
			pw.println(data.get(i));
		}
		
		pw.flush();
		pw.close();
	}
	
	public static void main(String[] args) throws IOException {

		ExampleIO exampleIO = new ExampleIO();
		List<String> data = exampleIO.readData();		
		exampleIO.saveData(data);
		

	}
	
}
